package com.myflink.day02;

import com.myflink.bean.WaterSensor;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;

/**
 * @author Shelly An
 * @create 2020/9/16 14:38
 */
public class Source_Collection {
    public static void main(String[] args) throws Exception {
        //0. 获取执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        //默认不是1，是电脑的线程数，一个core2个线程
        env.setParallelism(1);

        //1. Source 读取数据
        DataStreamSource<WaterSensor> sensorDataStreamSource = env.fromCollection(
                Arrays.asList(
                        new WaterSensor("s1", System.currentTimeMillis(), 41),
                        new WaterSensor("s2", System.currentTimeMillis(), 28),
                        new WaterSensor("s3", System.currentTimeMillis(), 36)
                )
        );

        //2. 打印
        sensorDataStreamSource.print();

        //3. 执行
        env.execute();
    }
}
